// 不知道数量级, 所以统计,相乘法, 来减少量级, 不在是双for, 而是单for
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m, n;
let arrM = [];
let arrN = [];
rl.on("line", (line)=>{
    if(m === undefined) {
        m = Number(line.trim())
    } else if(arrM.length === 0) {
        arrM = line.trim().split(" ").map(Number)
    } else if(n === undefined) {
        n = Number(line.trim())
    } else if (arrN.length === 0){
        arrN = line.trim().split(" ").map(Number);
        console.log(getResult(m, n, arrM, arrN));

        // clear
        m = n = undefined
        arrM.length = 0
        arrN.length = 0
    }
})

/**
 *  返回元祖数
 * @param m {number}
 * @param n {number}
 * @param arrM {[number]}
 * @param arrN {[number]}
 * @return {number}
 */
function getResult(m, n, arrM, arrN) {
    let objM = {}
    let objN = {}

    // 统计
    for (const num of arrM) {
        if(!objM.hasOwnProperty(num)) {
            objM[num] = 1
        } else {
            objM[num]++
        }
    }
    for (const num of arrN) {
        if(!objN.hasOwnProperty(num)) {
            objN[num] = 1
        } else {
            objN[num]++
        }
    }

    // 遍历
    let count = 0;
    for (const num of Object.keys(objM)) {
        if(objN.hasOwnProperty(num)) {
            count += objM[num] * objN[num];
        }
    }

    return count;
}